package com.invite.me.ui.yaoyue;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.invite.me.R;
import com.invite.me.base.BaseActivity;
import com.invite.me.beans.adpater.MySeetAdpater;
import com.invite.me.beans.bilnddatabean.MySeetBqBean;
import com.invite.me.beans.presenter.MyInfoEditPresenter;
import com.invite.me.beans.res.BlindDataParticularsBean;
import com.invite.me.beans.res.MyinfoEdittjBean;
import com.invite.me.beans.res.NameAtteastationtpBean;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.util.ToastUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class MyInfoEditActivity extends BaseActivity implements View.OnClickListener,Contract.BaseView {

    private RecyclerView addbiaoqianrecyclerview;
    MySeetAdpater mySeetAdpater;
    List<MySeetBqBean> list =new ArrayList<>();
    MyInfoEditPresenter myInfoEditPresenter;
    private int nannv;
    private LinearLayout nan;
    private LinearLayout nv;
    private BottomSheetDialog dialog;
    private String contents = "";
    private TextView nikename;
    private TextView qianbiaoji;
    private TextView qianxianshi;
    private TextView shangwuhuodong;
    private TextView xiangqin;
    private TextView wanghongyanchu;
    private TextView baocui;
    private Double qianpreice=null;
    private String yaoyuezhuatai="相亲";
    private String namezhuangtai=null;
    private String touxiangzhuangtai=null;

    private List<LocalMedia> selectList = new ArrayList<>();
    private List<String> biaoqian=new ArrayList<>();
    private TextView nanzi;
    private TextView nvzi;
    private ImageView touxiang;
    private ImageView nanbiaoji;
    private ImageView nvbiaoshi;

    List<BlindDataParticularsBean.DataBean.MyTagListBean> myTagList = new ArrayList<>();


    @Override
    protected void initView() {
        indata();
        myInfoEditPresenter=new MyInfoEditPresenter(this);
        myInfoEditPresenter.myxinxi();
        //TextProgressBar textProgressBar = findViewById(R.id.textProgressBar);
        // textProgressBar.setMax(1000);
        //  textProgressBar.setProgress(0);
        ImageView account_balance_fanhui = findViewById(R.id.account_balance_fanhui);
        ImageView xiangjipaizhao = findViewById(R.id.xiangjipaizhao);
        RelativeLayout price_xy = findViewById(R.id.price_xy);
        touxiang = findViewById(R.id.touxiang);
        baocui = findViewById(R.id.baocui);
        xiangqin = findViewById(R.id.xiangqin);
        wanghongyanchu = findViewById(R.id.wanghongyanchu);
        shangwuhuodong = findViewById(R.id.shangwuhuodong);
        qianbiaoji = findViewById(R.id.qianbiaoji);
        qianxianshi = findViewById(R.id.qianxianshi);
        nikename = findViewById(R.id.nikename);
        nanzi = findViewById(R.id.nanzi);
        nvzi = findViewById(R.id.nvzi);
        nanbiaoji = findViewById(R.id.nanbiaoji);
        nvbiaoshi = findViewById(R.id.nvbiaoshi);

        nan = findViewById(R.id.nan);
        nv = findViewById(R.id.nv);
        baocui.setOnClickListener(this);
        price_xy.setOnClickListener(this);
        nan.setOnClickListener(this);
        nv.setOnClickListener(this);
        xiangjipaizhao.setOnClickListener(this);
        nikename.setOnClickListener(this);
        xiangqin.setOnClickListener(this);
        wanghongyanchu.setOnClickListener(this);
        shangwuhuodong.setOnClickListener(this);

        account_balance_fanhui.setOnClickListener(this);
        addbiaoqianrecyclerview = findViewById(R.id.addbiaoqianrecyclerview);
        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        addbiaoqianrecyclerview.addItemDecoration(new SpaceItemDecoration(dp2px(5)));
        addbiaoqianrecyclerview.setLayoutManager(flowLayoutManager);
        mySeetAdpater=new MySeetAdpater(R.layout.myseet_listbiaoqian,list);
        addbiaoqianrecyclerview.setAdapter(mySeetAdpater);
        mySeetAdpater.notifyDataSetChanged();
        mySeetAdpater.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()){
                    case R.id.name:
                        boolean diaoqitankuang = list.get(position).isDiaoqitankuang();
                        if(diaoqitankuang){
                            showCommentDialog("xiaoxilist");

                        }else{
                            list.get(position).setDianji(true);
                            mySeetAdpater.notifyDataSetChanged();
                        }

                        break;
                    case R.id.chacha:
                        list.remove(position);
                        mySeetAdpater.notifyDataSetChanged();
                        break;

                }

            }
        });


    }

    @Override
    protected int getActivityLayoutId() {
        return R.layout.activity_myset;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.xiangjipaizhao:
                gerxiangce();

                break;
            case R.id.baocui:
                if(list.size()>1){
                    for (int i=0;i<list.size()-1;i++){
                        biaoqian.add(list.get(i).getName());
                    }
                }



                if(TextUtils.isEmpty(touxiangzhuangtai)){
                    ToastUtils.show(MyInfoEditActivity.this,"请上传头像");
                    return;
                }else if(TextUtils.isEmpty(namezhuangtai)){
                    ToastUtils.show(MyInfoEditActivity.this,"请上传昵称");
                    return;
                }else if(nannv<=0){
                    ToastUtils.show(MyInfoEditActivity.this,"请选择性别");
                    return;
                }else if(biaoqian.size()<=0){
                    ToastUtils.show(MyInfoEditActivity.this,"请添加基本情况");
                    return;
                }else if(TextUtils.isEmpty(yaoyuezhuatai)){
                    ToastUtils.show(MyInfoEditActivity.this,"请选择邀约类型");
                    return;
                }else if(qianpreice<=0){
                    ToastUtils.show(MyInfoEditActivity.this,"请选择邀约费");
                    return;
                }
                myInfoEditPresenter.tijiaoshimingrenzheng(touxiangzhuangtai,namezhuangtai,nannv,biaoqian,yaoyuezhuatai,qianpreice);

                biaoqian.clear();

                break;
            case R.id.xiangqin:
                xiangqin.setTextColor(Color.rgb(255,255,255));
                Resources xq = getResources();
                Drawable xqdb = xq.getDrawable(R.drawable.hongdper_yuan);
                xiangqin.setBackground(xqdb);
//                wanghongyanchu.setTextColor(Color.rgb(153,153,153));
//                Resources whyc =getResources();
//                Drawable whycdb = whyc.getDrawable(R.drawable.huixian_miaobian);
//                wanghongyanchu.setBackground(whycdb);
//                shangwuhuodong.setTextColor(Color.rgb(153,153,153));
//                Resources swhd =getResources();
//                Drawable swhddb = swhd.getDrawable(R.drawable.huixian_miaobian);
//                shangwuhuodong.setBackground(swhddb);
                yaoyuezhuatai="相亲";
                break;

            case R.id.wanghongyanchu:
                xiangqin.setTextColor(Color.rgb(153,153,153));
                Resources xqq = getResources();
                Drawable xqdbb = xqq.getDrawable(R.drawable.huixian_miaobian);
                xiangqin.setBackground(xqdbb);
                wanghongyanchu.setTextColor(Color.rgb(255,255,255));
                Resources whycc =getResources();
                Drawable whycdbb = whycc.getDrawable(R.drawable.hongdper_yuan);
                wanghongyanchu.setBackground(whycdbb);
                shangwuhuodong.setTextColor(Color.rgb(153,153,153));
                Resources swhdd =getResources();
                Drawable swhddbb = swhdd.getDrawable(R.drawable.huixian_miaobian);
                shangwuhuodong.setBackground(swhddbb);
                yaoyuezhuatai="歌手网红演出";
                break;
            case R.id.shangwuhuodong:
                xiangqin.setTextColor(Color.rgb(153,153,153));
                Resources xqx = getResources();
                Drawable xqdbx = xqx.getDrawable(R.drawable.huixian_miaobian);
                xiangqin.setBackground(xqdbx);
                wanghongyanchu.setTextColor(Color.rgb(153,153,153));
                Resources whycw=getResources();
                Drawable whycdbw = whycw.getDrawable(R.drawable.huixian_miaobian);
                wanghongyanchu.setBackground(whycdbw);
                shangwuhuodong.setTextColor(Color.rgb(255,255,255));
                Resources swhds =getResources();
                Drawable swhddbs = swhds.getDrawable(R.drawable.hongdper_yuan);
                shangwuhuodong.setBackground(swhddbs);
                yaoyuezhuatai="商务活动";
                break;

            case R.id.nikename:
                showCommentDialog("nikname");
                break;
            case R.id.price_xy:
                xuanzeqianpop();
                break;
            case R.id.account_balance_fanhui:
                finish();
                break;
            case R.id.nan:
                nannv=1;
                nvzi.setTextColor(Color.rgb(153,153,153));
                nanzi.setTextColor(Color.rgb(255,255,255));

                nanbiaoji.setImageResource(R.mipmap.nanbaitu);
                nvbiaoshi.setImageResource(R.mipmap.nxbs);
                Resources resources =getResources();
                Drawable drawable = resources.getDrawable(R.drawable.hongdper_yuan);
                nan.setBackground(drawable);
                Resources resourcesnv =getResources();
                Drawable drawablenv = resourcesnv.getDrawable(R.drawable.huixian_miaobian);
                nv.setBackground(drawablenv);
                break;
            case R.id.nv:
                nannv=2;
                nanzi.setTextColor(Color.rgb(153,153,153));
                nvzi.setTextColor(Color.rgb(255,255,255));
                nanbiaoji.setImageResource(R.mipmap.nanbiaoshi);
                nvbiaoshi.setImageResource(R.mipmap.nvbiaoshi);
                Resources resourcesnvnv =getResources();
                Drawable drawablenvv = resourcesnvnv.getDrawable(R.drawable.huixian_miaobian);
                nan.setBackground(drawablenvv);
                Resources resourcesnvr =getResources();
                Drawable drawablenvr = resourcesnvr.getDrawable(R.drawable.hongdper_yuan);
                nv.setBackground(drawablenvr);
                break;

        }


    }


    @Override
    protected void loadData() {

    }
    public void indata(){
        list.add(new MySeetBqBean("+输入新词用逗号分开 ",true));

    }
    private int dp2px(float value) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
    }


    @Override
    public void setPresenter(Contract.BasePresenter basePresenter) {
        if (myInfoEditPresenter instanceof Contract.BasePresenter) {
            this.myInfoEditPresenter = (MyInfoEditPresenter) basePresenter;
        }
    }

    @Override
    public void onDataSucess(Object o){
        if(o instanceof NameAtteastationtpBean){
            NameAtteastationtpBean nameAtteastationtpBean= (NameAtteastationtpBean) o;
            String data = nameAtteastationtpBean.getData();
            if(!TextUtils.isEmpty(data)){
                String aa= Constants.TP_URL+data;
                touxiangzhuangtai=aa;
                Glide.with(this)
                        .load(touxiangzhuangtai)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))//圆角半径
                        .into(touxiang);


            }
        }else if(o instanceof MyinfoEdittjBean){
            MyinfoEdittjBean myinfoEdittjBean= (MyinfoEdittjBean) o;
            if(myinfoEdittjBean.getCode()==1000){
                ToastUtils.show(MyInfoEditActivity.this,myinfoEdittjBean.getMessage());
                finish();
            }else {
                ToastUtils.show(MyInfoEditActivity.this,myinfoEdittjBean.getMessage());
            }


        }else if (o instanceof BlindDataParticularsBean){
            BlindDataParticularsBean blindDataParticularsBean= (BlindDataParticularsBean) o;
            if(blindDataParticularsBean.getCode()==1000){
                if(blindDataParticularsBean.getData()!=null){
                    String nickname = blindDataParticularsBean.getData().getNickname();
                    String discribe = blindDataParticularsBean.getData().getDiscribe();//头像
                    if(TextUtils.isEmpty(nickname)&&TextUtils.isEmpty(discribe)){
//                        Intent sz=new Intent(MyInfoActivity.this, MyInfoEditActivity.class);
//                        startActivity(sz);

                    }else{

                        int sex = blindDataParticularsBean.getData().getSex();
                        //  String intention = blindDataParticularsBean.getData().getIntention();
                        double price = blindDataParticularsBean.getData().getPrice();
                        SspPrefUtils.setString(Constants.NAKNAME,nickname);
                        //名字
                        namezhuangtai=nickname;
                        //头像
                        touxiangzhuangtai=discribe;
                        nikename.setText(nickname);
                        qianbiaoji.setVisibility(View.VISIBLE);

                        qianpreice=price;

                        qianxianshi.setText(price+"");
                        Glide.with(this)
                                .load(discribe)
                                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))//圆角半径
                                .into(touxiang);
                        if(sex==1){
                            nannv=1;
                            nvzi.setTextColor(Color.rgb(153,153,153));
                            nanzi.setTextColor(Color.rgb(255,255,255));

                            nanbiaoji.setImageResource(R.mipmap.nanbaitu);
                            nvbiaoshi.setImageResource(R.mipmap.nxbs);
                            Resources resources =getResources();
                            Drawable drawable = resources.getDrawable(R.drawable.hongdper_yuan);
                            nan.setBackground(drawable);
                            Resources resourcesnv =getResources();
                            Drawable drawablenv = resourcesnv.getDrawable(R.drawable.huixian_miaobian);
                            nv.setBackground(drawablenv);

                        }else if(sex==2){
                            nannv=2;
                            nanzi.setTextColor(Color.rgb(153,153,153));
                            nvzi.setTextColor(Color.rgb(255,255,255));
                            nanbiaoji.setImageResource(R.mipmap.nanbiaoshi);
                            nvbiaoshi.setImageResource(R.mipmap.nvbiaoshi);
                            Resources resourcesnvnv =getResources();
                            Drawable drawablenvv = resourcesnvnv.getDrawable(R.drawable.huixian_miaobian);
                            nan.setBackground(drawablenvv);
                            Resources resourcesnvr =getResources();
                            Drawable drawablenvr = resourcesnvr.getDrawable(R.drawable.hongdper_yuan);
                            nv.setBackground(drawablenvr);
                        }

                        myTagList.addAll(blindDataParticularsBean.getData().getMyTagList());

                        for (int i=0;i<myTagList.size();i++){
                            String title = myTagList.get(i).getTitle();
                            list.add(0,new MySeetBqBean(title,false));
                        }

                        mySeetAdpater.notifyDataSetChanged();
                    }







                }




            }




        }


    }

    @Override
    public void onDataFaile(Object o) {

    }

    @Override
    public void onComplete() {

    }

    public void xuanzeqianpop(){
        View parent = ((ViewGroup)this.findViewById(android.R.id.content)).getChildAt(0);
        View view = LayoutInflater.from(this).inflate(R.layout.myinfopop_list, null, false);
        ImageView chacha=view.findViewById(R.id.chacha);
        TextView yibai=view.findViewById(R.id.yibai);
        TextView erbai=view.findViewById(R.id.erbai);
        TextView sanbai=view.findViewById(R.id.sanbai);
        TextView wubai=view.findViewById(R.id.wubai);
        TextView yiqian=view.findViewById(R.id.yiqian);
        TextView zidingyi=view.findViewById(R.id.zidingyi);

        final PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, false);
        popupWindow.setFocusable(true);
        //产生背景变暗效果
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
        popupWindow.setOutsideTouchable(true);// 设置同意在外点击消失
        chacha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        yibai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianbiaoji.setVisibility(View.VISIBLE);
                qianxianshi.setText("100");
                qianpreice=100.0;
                popupWindow.dismiss();
            }
        });
        erbai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianbiaoji.setVisibility(View.VISIBLE);
                qianxianshi.setText("200");
                qianpreice=200.0;
                popupWindow.dismiss();
            }
        });
        sanbai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianbiaoji.setVisibility(View.VISIBLE);
                qianxianshi.setText("300");
                qianpreice=300.0;
                popupWindow.dismiss();
            }
        });
        wubai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianbiaoji.setVisibility(View.VISIBLE);
                qianxianshi.setText("500");
                qianpreice=500.0;
                popupWindow.dismiss();
            }
        });
        yiqian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianbiaoji.setVisibility(View.VISIBLE);
                qianxianshi.setText("1000");
                qianpreice=1000.0;
                popupWindow.dismiss();
            }
        });
        zidingyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                showCommentDialog("priceqian");

            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            //在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
                popupWindow.dismiss();
            }
        });
        popupWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    /**
     * 弹出评论框
     */
    private void showCommentDialog(final String xiaoxitype) {
        dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);


        View commentView = LayoutInflater.from(this).inflate(R.layout.teacher_zhibo_textpop, null);
        final EditText commentText = (EditText) commentView.findViewById(R.id.dialog_comment_et);
        final TextView bt_comment = (TextView) commentView.findViewById(R.id.dialog_comment_bt);
        final TextView text_Word_number = commentView.findViewById(R.id.text_Word_number);
        dialog.setContentView(commentView);


        if (!TextUtils.isEmpty(contents)) {
            commentText.setText(contents);
            if (!TextUtils.isEmpty(contents) && contents.length() > 0) {
                bt_comment.setTextColor(Color.parseColor("#FF0084FF"));
            } else {
                bt_comment.setTextColor(Color.parseColor("#FFB9DDFF"));
            }
            text_Word_number.setText(contents.length() + "/100字数");

            commentText.setSelection(contents.length());
        }

        /**
         * 解决bsd显示不全的情况
         */

        View parent = (View) commentView.getParent();
        final BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
        commentView.measure(0, 0);
        behavior.setPeekHeight(commentView.getMeasuredHeight());

        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(View view, int i) {
                //禁止拖拽，
                if (i == BottomSheetBehavior.STATE_DRAGGING) {
                    //设置为收缩状态
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }

            @Override
            public void onSlide(View view, float v) {

            }
        });


        commentText.setHint("输入文字");


        //按钮点击发送
        bt_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String content = commentText.getText().toString();

                if (!TextUtils.isEmpty(content)) {

                    if (xiaoxitype.equals("xiaoxilist")) {

                        list.add(0,new MySeetBqBean(content,false));
                        mySeetAdpater.notifyDataSetChanged();
                        contents = "";

                    } else if (xiaoxitype.equals("nikname")) {
                        nikename.setText(content+"");
                        namezhuangtai=content+"";
                        contents = "";

                    }else if(xiaoxitype.equals("priceqian")){

                        if(TextUtils.isDigitsOnly(content)){
                            Double integer = Double.valueOf(content);
                            qianpreice=integer;
                            qianxianshi.setText(content);
                            qianbiaoji.setVisibility(View.VISIBLE);
                        }else{
                            boolean doubleOrFloat = isDoubleOrFloat(content);
                            if(doubleOrFloat){
                                Double integer = Double.valueOf(content);
                                qianpreice=integer;
                                qianxianshi.setText(content);
                                qianbiaoji.setVisibility(View.VISIBLE);
                            }
                        }

                        contents = "";

                    }

                    dialog.dismiss();

                } else {
                    ToastUtils.show(MyInfoEditActivity.this, "输入不能为空");
                }


            }
        });

        commentText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (!TextUtils.isEmpty(charSequence) && charSequence.length() > 0) {
                    bt_comment.setTextColor(Color.parseColor("#FF0084FF"));
                } else {
                    bt_comment.setTextColor(Color.parseColor("#FFB9DDFF"));
                }
                text_Word_number.setText(charSequence.length() + "/20字数");
                if (!TextUtils.isEmpty(charSequence)) {
                    contents = charSequence + "";
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        dialog.show();

    }
    public static boolean isDoubleOrFloat(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
        return pattern.matcher(str).matches();
    }

    //相册
    private void gerxiangce() {
        PictureSelector.create(MyInfoEditActivity.this)
                .openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                //   .theme(R.style.)// 主题样式设置 具体参考 values/styles   用法：R.style.picture.white.style
                .maxSelectNum(1)// 最大图片选择数量
                .minSelectNum(1)// 最小选择数量
                .imageSpanCount(4)// 每行显示个数
                .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选
                .previewImage(true)// 是否可预览图片
                //  .previewVideo(cb_preview_video.isChecked())// 是否可预览视频
                //   .enablePreviewAudio(cb_preview_audio.isChecked()) // 是否可播放音频
                .isCamera(true)// 是否显示拍照按钮
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                //.imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                //.setOutputCameraPath("/CustomPath")// 自定义拍照保存路径
                .enableCrop(true)// 是否裁剪
                .compress(true)// 是否压缩
                .synOrAsy(true)//同步true或异步false 压缩 默认同步
                //.compressSavePath(getPath())//压缩图片保存地址
                .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                .glideOverride(160, 160)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
                .withAspectRatio(1, 1)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
                .hideBottomControls(false)// 是否显示uCrop工具栏，默认不显示
                // .isGif(cb_isGif.isChecked())// 是否显示gif图片
                .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
                //  .circleDimmedLayer(cb_crop_circular.isChecked())// 是否圆形裁剪
                .showCropFrame(true)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
                .showCropGrid(true)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
                .openClickSound(true)// 是否开启点击声音
                //  .selectionMedia(selectList)// 是否传入已选图片
                .isDragFrame(true)// 是否可拖动裁剪框(固定)
                .videoMaxSecond(15)
                .videoMinSecond(10)
                //.previewEggs(false)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中)
                .cropCompressQuality(90)// 裁剪压缩质量 默认100
                .minimumCompressSize(50)// 小于100kb的图片不压缩
                .cropWH(100,200)// 裁剪宽高比，设置如果大于图片本身宽高则无效
                //   .rotateEnabled(true) // 裁剪是否可旋转图片
                .scaleEnabled(true)// 裁剪是否可放大缩小图片
                //.videoQuality()// 视频录制质量 0 or 1
                //.videoSecond()//显示多少秒以内的视频or音频也可适用
                //.recordVideoSecond()//录制视频秒数 默认60s
                .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        switch (requestCode) {
            case PictureConfig.CHOOSE_REQUEST:
                selectList = PictureSelector.obtainMultipleResult(data);
                String path = "";

                for (int i = 0; i < selectList.size(); i++) {
                    LocalMedia media = selectList.get(i);
                    if (media.isCut() && !media.isCompressed()) {
                        // 裁剪过
                        path = media.getCutPath();
                    } else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
                        // 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
                        path = media.getCompressPath();
                    } else {
                        // 原图
                        path = media.getPath();
                    }
                    File file = new File(path);
                    //   文件上传
                    myInfoEditPresenter.shangchuanweijian(file, "1");
                }


                break;
        }
        super.onActivityResult(requestCode, resultCode, data);

    }




}
